Skip to content

GH-37096: [MATLAB] Add utility which makes valid MATLAB table variable names from an arbitrary list of strings - #37098

Merged
kevingurney merged 8 commits into
apache:mainfrom
mathworks:GH-37096
Aug 10, 2023
Merged

kevingurney merged 8 commits into
apache:mainfrom
mathworks:GH-37096

Conversation

@sgilmore10

@sgilmore10 sgilmore10 commented Aug 9, 2023 •

Copy link
Copy Markdown
Member

Rationale for this change

To make it possible to safely convert Arrow Schema field names to corresponding MATLAB table variable names, it would be helpful to add a utility which can take an arbitrary list of strings and return a set of valid MATLAB table variable names, which are (1) unique, (2) non-empty, and (3) do not conflict with the "reserved" variable names "Properties", "VariableNames", "RowNames", and ":". An additional restriction is that variable names must have 63 or less characters.

What changes are included in this PR?

  1. Added a new function called arrow.tabular.internal.makeValidVariableNames that accepts an arbitrary list of strings and returns valid MATLAB table variable names.
>> originalVarNames = ["", "Properties", ":", "ValidVar", "ValidVar"];
>> validVarNames = arrow.tabular.internal.makeValidVariableNames(originalVarNames)

validVarNames = 

  1×5 string array

    "Var1"    "Properties_1"    ":_1"    "ValidVar"    "ValidVar_1"
  1. Added a new function called arrow.tabular.internal.makeValidDimensionNames that returns valid table dimension names with respect to a list of valid variable names. In MATLAB the default table dimension names are "Row" and "Variables", but they must not conflict with any variables names. In other words, they must be unique with respect to the variable names.
>> validVarNames = ["Row" "Test" "Variables"];
>> validDimNames = arrow.tabular.internal.makeValidDimensionNames(validVarNames)

validDimNames = 

  1×2 string array

    "Row_1"    "Variables_1"

To summarize, MATLAB tables cannot have arbitrary variable names. For example, "Properties", "RowNames", "VariableNames", and ":" are all disallowed. Variable names must also be unique and must be between 1 and 63 characters in length. They also must be unique with respect to each other.

Are these changes tested?

Yes. Added the following new test classes:

  1. tMakeValidVariableNames.m
  2. tMakeValidDimensionNames.m

Are there any user-facing changes?

No.

Future Directions

  1. In a follow-up PR, we will integrate makeValidVariableNames and makeValidDimensionNames into the table() and toMATLAB() methods of arrow.tabular.RecordBatch.

Notes

Thanks to @kevingurney for help writing the test cases!

@kevingurney kevingurney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @sgilmore10! I just had a few minor comments.

@kevingurney

Copy link
Copy Markdown
Member

+1

@kevingurney
kevingurney merged commit 8ab6484 into apache:main Aug 10, 2023
@kevingurney
kevingurney deleted the GH-37096 branch August 11, 2023 15:03
@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit 8ab6484.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

kevingurney added a commit that referenced this pull request Aug 14, 2023
…onNames` in implementation of `table` method for `RecordBatch` (#37152)

### Rationale for this change

#37098 added utilities for making valid MATLAB `table` `VariableNames` (`makeValidVariableNames`) and `DimensionNames` (`makeValidDimensionNames`) from an arbitrary list of strings.

This pull request uses these utilities to ensure that `RecordBatch` field names are converted to valid MATLAB `table` `VariableNames`/`DimensionNames` when calling the `table`/`toMATLAB` methods.

### What changes are included in this PR?

1. Used `makeValidVariableNames` and `makeValidDimensionNames` utilities in the implementation of the `table` method for the `RecordBatch` class to ensure that column names are converted to valid MATLAB `table` `VariableNames`/`DimensionNames`.

### Are these changes tested?

Yes.

1. The existing tests in `arrow/matlab/test/arrow/tabular/tMakeValidVariableNames.m` and `arrow/matlab/test/arrow/tabular/tMakeValidDimensionNames.m` already test that an arbitrary list of column names are converted into valid MATLAB `table` `VariableNames`/`DimensionNames`.
2. There is currently no straightforward way to create a `RecordBatch` with field names that are invalid MATLAB `VariableNames`/`DimensionNames` using the MATLAB interface. When we have a way to do this in the MATLAB interface, we can add more "integration" tests which verify that a `RecordBatch` with field names that are invalid MATLAB `table` `VariableNames`/`DimensionNames` are converted into valid `VariableNames`/`DimensionNames` when the `table`/`toMATLAB` methods are called.

### Are there any user-facing changes?

Yes.

A `RecordBatch` with field names that are invalid MATLAB `table` `VariableNames`/`DimensionNames` will now be converted into a MATLAB `table` with valid `VariableNames`/`DimensionNames` when calling the `table`/`toMATLAB` methods.

### Future Directions

1. #37046 (this change to the `table` method of the `RecordBatch` class should help preserve the behavior of storing original `RecordBatch` field names in the `VariableDescriptions` property of the output MATLAB `table` returned by `featherread`).
* Closes: #37151

Authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this pull request Nov 13, 2023
…ariable names from an arbitrary list of strings (apache#37098)

### Rationale for this change

To make it possible to safely convert Arrow Schema field names to corresponding MATLAB `table` variable names, it would be helpful to add a utility which can take an arbitrary list of strings and return a set of valid MATLAB `table` variable names, which are (1) unique, (2) non-empty, and (3) do not conflict with the "reserved" variable names "Properties", "VariableNames", "RowNames", and ":". An additional restriction is that variable names must have 63 or less characters. 

### What changes are included in this PR?

1. Added a new function called `arrow.tabular.internal.makeValidVariableNames` that accepts an arbitrary list of strings and returns valid MATLAB `table` variable names.

```matlab
>> originalVarNames = ["", "Properties", ":", "ValidVar", "ValidVar"];
>> validVarNames = arrow.tabular.internal.makeValidVariableNames(originalVarNames)

validVarNames = 

  1×5 string array

    "Var1"    "Properties_1"    ":_1"    "ValidVar"    "ValidVar_1"
```

3. Added a new function called `arrow.tabular.internal.makeValidDimensionNames` that returns valid table dimension names with respect to a list of valid variable names. In MATLAB the default `table` dimension names are `"Row"` and `"Variables"`, but they must not conflict with any variables names. In other words, they must be unique with respect to the variable names. 

```matlab
>> validVarNames = ["Row" "Test" "Variables"];
>> validDimNames = arrow.tabular.internal.makeValidDimensionNames(validVarNames)

validDimNames = 

  1×2 string array

    "Row_1"    "Variables_1"
```

To summarize, MATLAB `table`s cannot have arbitrary variable names. For example, `"Properties"`, `"RowNames"`, `"VariableNames"`, and `":"` are all disallowed. Variable names must also be unique and must be between 1 and 63 characters in length. They also must be unique with respect to each other.

### Are these changes tested?

Yes. Added the following new test classes:

1. `tMakeValidVariableNames.m`
2. `tMakeValidDimensionNames.m`

### Are there any user-facing changes?

No.

### Future Directions

1. In a follow-up PR, we will integrate `makeValidVariableNames` and `makeValidDimensionNames` into the `table()` and `toMATLAB()` methods of `arrow.tabular.RecordBatch`.

### Notes

Thanks to @ kevingurney for help writing the test cases!

* Closes: apache#37096

Lead-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Co-authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
loicalleyne pushed a commit to loicalleyne/arrow that referenced this pull request Nov 13, 2023
…imensionNames` in implementation of `table` method for `RecordBatch` (apache#37152)

### Rationale for this change

apache#37098 added utilities for making valid MATLAB `table` `VariableNames` (`makeValidVariableNames`) and `DimensionNames` (`makeValidDimensionNames`) from an arbitrary list of strings.

This pull request uses these utilities to ensure that `RecordBatch` field names are converted to valid MATLAB `table` `VariableNames`/`DimensionNames` when calling the `table`/`toMATLAB` methods.

### What changes are included in this PR?

1. Used `makeValidVariableNames` and `makeValidDimensionNames` utilities in the implementation of the `table` method for the `RecordBatch` class to ensure that column names are converted to valid MATLAB `table` `VariableNames`/`DimensionNames`.

### Are these changes tested?

Yes.

1. The existing tests in `arrow/matlab/test/arrow/tabular/tMakeValidVariableNames.m` and `arrow/matlab/test/arrow/tabular/tMakeValidDimensionNames.m` already test that an arbitrary list of column names are converted into valid MATLAB `table` `VariableNames`/`DimensionNames`.
2. There is currently no straightforward way to create a `RecordBatch` with field names that are invalid MATLAB `VariableNames`/`DimensionNames` using the MATLAB interface. When we have a way to do this in the MATLAB interface, we can add more "integration" tests which verify that a `RecordBatch` with field names that are invalid MATLAB `table` `VariableNames`/`DimensionNames` are converted into valid `VariableNames`/`DimensionNames` when the `table`/`toMATLAB` methods are called.

### Are there any user-facing changes?

Yes.

A `RecordBatch` with field names that are invalid MATLAB `table` `VariableNames`/`DimensionNames` will now be converted into a MATLAB `table` with valid `VariableNames`/`DimensionNames` when calling the `table`/`toMATLAB` methods.

### Future Directions

1. apache#37046 (this change to the `table` method of the `RecordBatch` class should help preserve the behavior of storing original `RecordBatch` field names in the `VariableDescriptions` property of the output MATLAB `table` returned by `featherread`).
* Closes: apache#37151

Authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MATLAB] Add utility which makes valid MATLAB table variable names from an arbitrary list of strings

2 participants